package com.qmds.deviceserver.type.service.impl;

import com.qmds.common.core.entity.DeviceType;
import com.qmds.common.core.vo.R;
import com.qmds.deviceserver.type.dao.DeviceTypeMapper;
import com.qmds.deviceserver.type.param.DeviceTypeAddParam;
import com.qmds.deviceserver.type.service.DeviceTypeService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * --- 代码敲烂 月薪过万 ---
 *
 * @author ShiJiaWei
 * @date 2024/9/9
 * @desc:
 */
@Service
public class DeviceTypeServiceImpl implements DeviceTypeService {
    @Resource
    private DeviceTypeMapper deviceTypeMapper;

    @Override
    public R<List<DeviceType>> findAll() {
        List<DeviceType> deviceTypes = deviceTypeMapper.selectList(null);
        if (deviceTypes != null) {
            return R.ok(deviceTypes);
        }
        return R.fail();
    }

    @Override
    public R<Integer> addDeviceType(DeviceTypeAddParam typeParam) {
        if (typeParam == null) {
            return R.fail("参数有误");
        }
        DeviceType deviceType = new DeviceType();
        BeanUtils.copyProperties(typeParam, deviceType);
        if(deviceTypeMapper.insert(deviceType) > 0) {
            return R.ok();
        }
        return R.fail();
    }
}
